﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YJKSparseDistance.ControlLayer;
using YJKSparseDistance.ModelLayer;
using YJKInspectModelFunc.ModelLayer;

namespace YJKSparseDistance
{
	[Transaction(TransactionMode.Manual)]
	internal class TestCmd_RunWayCalculate : IExternalCommand
	{
		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			UIApplication application = commandData.Application;
			Application application2 = application.Application;
			UIDocument activeUIDocument = application.ActiveUIDocument;
			Document document = activeUIDocument.Document;
			IntPtr mainWindowHandle = Process.GetCurrentProcess().MainWindowHandle;
			List<Level> list = new List<Level>();
			List<Phase> list2 = new List<Phase>();
			list.Add(activeUIDocument.ActiveView.GenLevel);
			foreach (object obj in document.Phases)
			{
				Phase item = (Phase)obj;
				list2.Add(item);
			}
			List<List<ResultBean>> list3 = new AreaCalculateManger(new AreaGeter().GetAreas(document, list, new List<ICloseCurveAnalays>(), list2)[0]).CalculateAsync();
			Transaction transaction = new Transaction(document, "test");
			transaction.Start();
			foreach (List<ResultBean> list4 in list3)
			{
				foreach (ResultBean resultBean in list4)
				{
					if (resultBean.StartPoint.IfFinalEnd)
					{
						foreach (Line line in resultBean.GetLines())
						{
							document.Create.NewDetailCurve(activeUIDocument.ActiveView, line);
						}
					}
				}
			}
			transaction.Commit();
			return Autodesk.Revit.UI.Result.Succeeded;
		}
	}
}
